﻿using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace z.r {
	/// <summary>
	/// Interaction logic for Report.xaml
	/// </summary>
	public partial class ReportViewer : Window {
		public ReportViewer() {
			InitializeComponent();
		}
		private DateTime Date0, Date1;
		private string type;
		public ReportViewer(string type,DateTime Date0, DateTime Date1 = new DateTime()) {
			this.type = type;
			this.Date0 = Date0;
			this.Date1 = Date1;
			InitializeComponent();
		}
		private void _this_Loaded(object sender, RoutedEventArgs e) {
			ReportDataSource reportDataSource1 = new ReportDataSource();
			m.DataSet dataset = new m.DataSet();
			m.DataSetTableAdapters.TCTableAdapter mTA;
			dataset.BeginInit();
			reportDataSource1.Name = "DataSet1"; //Name of the report dataset in our .RDLC file
			reportDataSource1.Value = dataset.TC;
			rv1.LocalReport.DataSources.Add(reportDataSource1);
			switch (type) {
				case "dates":
					rv1.LocalReport.ReportEmbeddedResource = "z.r.TCDates.rdlc";
					rv1.LocalReport.SetParameters(new ReportParameter("Date_Begin", Date0.ToString("dd/MM/yyyy")));
					rv1.LocalReport.SetParameters(new ReportParameter("Date_End", Date1.ToString("dd/MM/yyyy")));
					break;
				case "month":
					rv1.LocalReport.ReportEmbeddedResource = "z.r.TCMonth.rdlc";
					Date0 = new DateTime(Date0.Year, Date0.Month, 1);
					Date1 = Date0.AddMonths(1);
					rv1.LocalReport.SetParameters(new ReportParameter("month", Date0.ToString("MM")));
					break;
				case "year":
					rv1.LocalReport.ReportEmbeddedResource = "z.r.TCYear.rdlc";
					Date0 = new DateTime(Date0.Year, 1, 1);
					Date1 = Date0.AddYears(1);
					rv1.LocalReport.SetParameters(new ReportParameter("year", Date0.ToString("yyyy")));
					break;
			}
			dataset.EndInit();
			mTA = new m.DataSetTableAdapters.TCTableAdapter();
			mTA.Connection = new System.Data.SqlClient.SqlConnection(Properties.Settings.Default.ConnectSting);
			mTA.ClearBeforeFill = true;
			mTA.Fill(dataset.TC, Date0, Date1);
			rv1.RefreshReport();
		}
	}
}
